package bavaria.hightech.testit;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;

import bavaria.hightech.b2b.BankRegistry;
import bavaria.hightech.banking.Account;
import bavaria.hightech.banking.BankImpl;
import bavaria.hightech.banking.ECurrency;
import bavaria.hightech.banking.Money;
import bavaria.hightech.exception.WrongValueException;
import bavaria.hightech.timer.InternalClock;

public class B2BTest {
	private static InternalClock timer;
	private static BankRegistry bankRegistryInstance;
	
	/**
	 * @param args
	 * @throws WrongValueException 
	 */
	public static void main(String[] args) throws WrongValueException {
		timer = InternalClock.getInstance();
		bankRegistryInstance = BankRegistry.getInstance();
		
		bankRegistryInstance.bind("Sparkasse", new BankImpl("de", "de"));
		bankRegistryInstance.bind("British Bank", new BankImpl("en", "uk"));
		
		Account a = ((BankImpl)bankRegistryInstance.lookup("Sparkasse")).openCurrentAccount("Daniel Fuss");
		Account b = ((BankImpl)bankRegistryInstance.lookup("British Bank")).openCurrentAccount("Christian Adler");
		
		((BankImpl)bankRegistryInstance.lookup("Sparkasse")).cashInValue(a.getAccountNumber(), new Money(1000, ECurrency.EUR), "Einzahlung");
		((BankImpl)bankRegistryInstance.lookup("British Bank")).cashInValue(b.getAccountNumber(), new Money(500, ECurrency.EUR), "Einzahlung");
		OutputStream out;
		try {
			out = new FileOutputStream("./statementB2BSparkasse.htm");
			((BankImpl)bankRegistryInstance.lookup("Sparkasse")).statement(a.getAccountNumber(), out, "text/html" ,"Date");
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		
		try {
			out = new FileOutputStream("./statementB2BBritish.htm");
			((BankImpl)bankRegistryInstance.lookup("British Bank")).statement(a.getAccountNumber(), out, "text/html" ,"Date");
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		
		((BankImpl)bankRegistryInstance.lookup("Sparkasse")).transfer("British Bank", a.getAccountNumber(), b.getAccountNumber(), new Money(750, ECurrency.EUR));
		try {
			out = new FileOutputStream("./statementB2BSparkasse.txt");
			((BankImpl)bankRegistryInstance.lookup("Sparkasse")).statement(a.getAccountNumber(), out, "text/plain" ,"Date");
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		
		try {
			out = new FileOutputStream("./statementB2BBritish.txt");
			((BankImpl)bankRegistryInstance.lookup("British Bank")).statement(a.getAccountNumber(), out, "text/plain" ,"Date");
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		
		((BankImpl)bankRegistryInstance.lookup("Sparkasse")).transfer("British Bank", a.getAccountNumber(), 123451, new Money(50, ECurrency.USD));
		try {
			out = new FileOutputStream("./statementB2BSparkasse.txt");
			((BankImpl)bankRegistryInstance.lookup("Sparkasse")).statement(a.getAccountNumber(), out, "text/plain" ,"Date");
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
	}

}
